import { ref } from "vue";
import * as echarts from "echarts";
//ts
interface propties {
  [propName: string]: any;
}
export const initEcharts = function (selectors = "", options = {}) {
  let Echart = echarts;
  let contentEle: HTMLElement | null = document.getElementById(`${selectors}`);
  if (contentEle) {
    let MyEchart: propties = Echart.init(contentEle, "");
    MyEchart.clear();
    MyEchart.setOption(options, true);
    MyEchart.resize();
    window.addEventListener("resize", () => {
      // 第六步，执行echarts自带的resize方法，即可做到让echarts图表自适应
      MyEchart.resize();
    });
    return MyEchart;
  } else {
    throw new Error("因为切换页面，容器可能已不存在！！");
  }
};
